package chapter10Daemon;

/**
 * 线程的优先级 1~10 默认是5 1最低优先级 10最高优先级
 * Created by LinGer on 2019/6/19
 */
public class PriorityTest extends Thread{

    public PriorityTest(String name){
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(this.getName() + " priority: " + this.getPriority() + " loop " + i);
        }
    }

    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName() + " priority: " + Thread.currentThread().getPriority());

        Thread t1 = new PriorityTest("t1");
        Thread t2 = new PriorityTest("t2");

        //设置线程优先级
        t1.setPriority(1);
        t2.setPriority(10);

        t1.start();
        t2.start();
    }
}
